package com.acme.bankapp.domain.bank;

/**
 * This is checking variant of particular implementation of abstract account
 * 
 * @author Anton Kotov
 * 
 */
public class CheckingAccount extends AbstractAccount {

	private double overdraft;

	public CheckingAccount(final int id, final double amount,
			final double overdraft) {
		super(id, amount);
		this.overdraft = overdraft;
	}

	public void withdraw(final double amount) {
		if (amount > getBalance()) {
			if (overdraft >= amount - getBalance()) {
				overdraft -= (amount - getBalance());
				balance = 0.;
			}
		} else {
			balance -= amount;
		}
	}

	@Override
	public double maximumAmountToWithdraw() {
		return getBalance() + overdraft;
	}
}
